<template>
    <div class="parcelList mailList applyList">
        <Form ref="queryForm" :model="queryForm" inline :label-width="140" class="search-form rui-query-form">
            <div class="applyQuerySearchRow">
                <div class="applyQueryHead">
                    <Button @click="addFareMail()" type="primary" class="btn" size="default">新增运单邮寄</Button>
                </div>
                <div class="applyQuerySearchItem">
                    <Form-item label="" prop="socUniCrtCode">
                        <div>
                            <Input prefix="ios-search" type="text" v-model="queryForm.postNo" @keyup.enter.native="handleSearch" clearable placeholder="运单编号"/>
                        </div>
                    </Form-item>
                </div>
            </div>
        </Form>
        <div class="table-card">
            <div class="btn-status flex flex-between">
                <div class="loanApplyBtn">
                </div>
            </div>
            <div class="rui-table-box">
                <Table stripe :columns="mailColumns" :data="mailList">
                    <template slot-scope="{ row }" slot="postNo">
                        <span @click="linkDetail(row.postNo)">{{ row.postNo }}</span>
                    </template>
                </Table>
            </div>
            <br/>
            <Row type="flex" justify="end">
                <Page :current="pageData.pageNumber" :transfer="true" :total="pageData.total" :page-size="pageData.pageSize" @on-change="changePage"
                      @on-page-size-change="changePageSize" :page-size-opts="pageSizeOpts" size="small" show-total
                      show-elevator show-sizer></Page>
            </Row>
        </div>
        <div v-if="isShowWayBill">
            <waybill-model
                @close-model="closeModel"
                @showRegisterMail="showRegisterMail"
                :operType="operType"
                :pcompanyList="pcompanyList"
            ></waybill-model>
        </div>
    </div>
</template>
<script>
     import {
        getmailList,
        getCodes,
        getPostInfo
    } from "_p/afs-apply/api/mail-manage/orderMailList.js";
    import "../../assets/css/base.css";
    import {orderMail} from '_p/afs-apply/assets/js/staticData.js'
    import RegisterMail from "../mail-manage//mail-register/registerMail.vue"
    import waybillModel from "../mail-manage/waybill-model/waybillModel.vue"
    import codeList from "_p/afs-apply/api/mail-manage/json/getcodes.json"
    import mailList from "_p/afs-apply/api/mail-manage/json/getlist.json"
    import {
    getDictDataByType
} from "_p/basic/api/admin/datadic.js";
     export default {
        name: "mailList",
        data(){
            return{
                archiveStatus:"",
                operType:"add",
                isShowWayBill:false,
                queryForm:{
                    pUserId:"",
                    postNo:"",
                    pDate:"",
                    dataType:"",
                },
                queryFormValiate:{

                },
                pageData:{
                    pageNumber:1,
                    pageSize:10,
                    total:0
                },
                dataTypeList:[],
                pcompanyList:[],
                mailColumns:[
                    {
                        type:"index",
                        title: '序号',
                    },
                    {
                        title: '快递公司',
                        key: 'pcompanyname'
                    },
                    {
                        title: '运单编号',
                        slot: 'postNo',
                        className:"postNoColor",

                    },
                    {
                        title: '邮寄时间',
                        key: 'pDate'
                    },
                    {
                        title:"寄件人",
                        key:"pUserId"
                    },
                    // {
                    //     title:"资料类型",
                    //     key:"dataType",
                    // },
                    {
                        title:"邮寄状态",
                        key:"statusName",
                    },

                ],
                mailList:[

                ],
                pageSizeOpts:[10,20,50,100],
            }
        },
        components:{
            RegisterMail,
            waybillModel
        },
        computed: {

        },
        created(){

        },
        mounted(){
            this.initData();
            this.queryMailList();
        },
        methods:{
            initData(){
                let param={
                    obj:{
                        "typeId":"",
                    }
                }
                getCodes(param).then(res=>{
                    if (res.code == "0000") {
                        this.pcompanyList=res.data['00001HKYK9DD40000A23'];
                    }
                })
            },
            // 查询最新运单信息
            queryPostInfo(){
                let param={
                }
                getPostInfo(param).then(res=>{
                    if(res.code=="0000"){
                        if(res.data){
                            if(res.data.id){
                                this.afs.newTab(this,'projects/afs-apply/pages/mail-manage/mail-register/registerMail','登记邮寄信息','ios-add',{id:res.data.id},'register-mail',[],true)
                            }else{
                                this.isShowWayBill=true;
                                this.$emit("open-model")
                            }
                        }
                    }
                })
            },
            // 查询邮单列表
            queryMailList(){
                let params={
                    pageIndex:this.pageData.pageNumber,
                    pageSize:this.pageData.pageSize,
                    postNo:this.queryForm.postNo,
                }
                getmailList(params).then(res=>{
                    // 当返回成功的时候
                    if(res.code=="0000"){
                        this.pageData.total=res.recordsTotal;
                        let tempArr=[];
                        res.data.records.forEach((item,index)=>{
                            let obj={
                                id:item.id,
                                pcompanyname:item.refData.pcompanyname,
                                postNo:item.postNo,
                                pDate:item.pdate,
                                pUserId:item.puserId,
                                statusName:item.refData.statusName
                            }
                            tempArr.push(obj);
                        })
                        this.mailList=tempArr;
                        this.pageData.total=res.data.total;
                    }
                })
            },
            handleSearch(){
                this.pageData.pageNumber=1;
                this.queryMailList()
            },
            handleReset(){
                this.$refs['queryForm'].resetFields();
                this.queryMailList();
            },
            addFareMail(){
                this.queryPostInfo();
            },
            changePage(number){
                this.pageData.pageNumber=number;
                this.queryMailList();
            },
            changePageSize(size){
                this.pageData.pageSize=size;
                this.queryMailList();
            },
            // 关闭创建运单弹框
            closeModel(value){
                this.isShowWayBill=value;
            },
            // 跳转邮包详情
            linkDetail(postNo){
                this.afs.newTab(this,'projects/afs-apply/pages/parcel-manage/parcel-detail/parcelDetail','邮包详情','ios-add',{postno:postNo},'pracel-detail',[],true)
            },
            // 保存运单信息
            showRegisterMail(id){
                this.isShowWayBill=false;
                this.afs.newTab(this,'projects/afs-apply/pages/mail-manage/mail-register/registerMail','登记邮寄信息','ios-add',{id:id},'register-mail',[],true)
            },
        }
     }
</script>
<style>
.ivu-table .ivu-table-body .postNoColor span{
    color:#EB9620;
    cursor: pointer;
}
</style>
<style scoped>
.page{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.postNo>>>.ivu-form-item-content{
    font-size: 0;
}
.postNo>>>.ivu-form-item-error-tip{
    font-size: 12px;
}
</style>
<style lang="less" scoped>
@import "../../assets/css/applyList.less";
</style>
